package com.video.web.controller.system;

import java.util.List;
import java.util.stream.Collectors;

import com.video.common.core.domain.entity.SysRole;
import com.video.common.core.domain.entity.SysUser;
import com.video.common.utils.StringUtils;
import com.video.system.domain.VideoCategory;
import com.video.system.domain.VideoTeacher;
import com.video.system.service.IVideoCategoryService;
import com.video.system.service.IVideoTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoCourse;
import com.video.system.service.IVideoCourseService;
import com.video.common.utils.poi.ExcelUtil;

/**
 * 视频管理Controller
 * 
 * @author lyh
 * @date 2021-08-03
 */
@Api("视频管理控制器")
@RestController
@RequestMapping("/system/course")
public class VideoCourseController extends BaseController
{
    @Autowired
    private IVideoCourseService videoCourseService;
    @Autowired
    private IVideoTeacherService videoTeacherService;
    @Autowired
    private IVideoCategoryService videoCategoryService;

    /**
     * 查询视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:course:list')")
    @GetMapping("/list")
    public AjaxResult list(VideoCourse videoCourse)
    {
        List<VideoCourse> list = videoCourseService.selectVideoCourseList(videoCourse);
        return AjaxResult.success(list);
    }

    /**
     * 导出视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:course:export')")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoCourse videoCourse)
    {
        List<VideoCourse> list = videoCourseService.selectVideoCourseList(videoCourse);
        ExcelUtil<VideoCourse> util = new ExcelUtil<VideoCourse>(VideoCourse.class);
        return util.exportExcel(list, "视频管理数据");
    }

    /**
     * 获取视频管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:query')")
    @GetMapping(value = {"/", "/{cId}"})
    @ApiOperation(value="获取视频管理详细信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = AjaxResult.class,
            notes="获取视频管理详细信息")
    public AjaxResult getInfo(@PathVariable(value = "cId", required = false) Integer cId)
    {
        System.out.println("=========================================");
        AjaxResult ajax = AjaxResult.success(videoCourseService.selectVideoCourseById(cId));
        List<VideoCategory> videoCategories = videoCategoryService.selectCodeAndNameList();
        List<VideoTeacher> videoTeachers = videoTeacherService.selectCodeAndNameList();
        ajax.put("category",videoCategories);
        ajax.put("teacher",videoTeachers);
        System.out.println("============================>"+videoCategories);
        System.out.println("============================>"+videoTeachers);
        System.out.println("=============================>"+ajax);
        return ajax;
        //return AjaxResult.success(videoCourseService.selectVideoCourseById(cId));
    }


    /**
     * 新增视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:course:add')")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="视频管理添加",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = AjaxResult.class,
            notes="视频管理添加模块")
    public AjaxResult add(@RequestBody VideoCourse videoCourse)
    {
        return toAjax(videoCourseService.insertVideoCourse(videoCourse));
    }

    /**
     * 修改视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:course:edit')")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoCourse videoCourse)
    {
        return toAjax(videoCourseService.updateVideoCourse(videoCourse));
    }

    /**
     * 删除视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:course:remove')")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Integer[] cIds)
    {
        return toAjax(videoCourseService.deleteVideoCourseByIds(cIds));
    }
}
